<template>
  <t-dialog
    :header="header"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    @confirm="onSubmit"
    :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }"
    mode="full-screen"
    width="90%"
    top="5%"
  >
      <div style="height: 80vh;">
        <template v-if="row.reviewType==='1'">
          <project-detail-dialog  :reviewOpen="true" :hideInfo="true" v-if="row.reviewType==='1'" :isDialog="false" :header="row.project.projectName" :objId="row.project.id" :visible.sync="dialog.open_project_detail"></project-detail-dialog>
        </template>
        <template v-else-if="row.reviewType==='2'">
          <t-row v-if="closeChangeDiff" :gutter="12">
            <t-col v-if="!closeDiff" :span="6">
              <t-tag size="large" variant="light" theme="primary">申报详情</t-tag>
              <project-detail-dialog :reviewOpen="true" :hideByProjectType="true" :hideInfo="false"  :isDialog="false" :header="row.project.projectName" :objId="row.project.id" :visible.sync="dialog.open_project_detail"></project-detail-dialog>
            </t-col>
            <t-col :span="closeDiff?12:6">
              <t-tag size="large" variant="light" theme="primary">大纲详情</t-tag>
              <t-tag size="large" variant="light" style="margin-left: 10px" theme="danger">
                红色部分对应项目数据->大纲数据变化(目前只标注了基本信息、经费预算)
              </t-tag>
              <outline-detail-dialog :contrastOpen="true" :reviewOpen="true" :hideByProjectType="true"  :isDialog="false" :header="row.project.projectName" :objId="row.project.id" :visible.sync="dialog.open_outline_detail"></outline-detail-dialog>
            </t-col>
          </t-row>
          <vertical-outline-detail v-else :contrastOpen="true" :reviewOpen="true" :isDialog="false" :header="row.project.projectName"
                                    :objId="row.project.id"
                                    :visible.sync="dialog.open_outline_detail"></vertical-outline-detail>
        </template>
        
        <acceptance-detail-dialog :reviewOpen="true" v-else-if="row.reviewType==='3'" :isDialog="false"  :header="row.project.projectName" :objId="row.project.id" :visible.sync="dialog.open_acceptance_detail" ></acceptance-detail-dialog>
        <item-detail v-else-if="['4','5'].includes(row.reviewType)" :reviewOpen="true" :hideInfo="true" :header="row.project.projectName" :objId="row.project.id"></item-detail>

        <div v-else>待完善</div>
          <t-drawer
            :visible="drawerVisible"
            showInAttachedElement
            :showOverlay="false"
            size="30%"
            :preventScrollThrough="false"
            header="评审内容"
          >
          <edit-expert-review @reload="reload" ref="edit-expert-review"  :editOpen="editOpen" :expertEditOpen="expertEditOpen" :reviewType="row.reviewType" :objId="row.id" :teamId="row.teamId" :expertUserId="row.experts.userId" :visible.sync="dialog.open_review"></edit-expert-review>
            <template v-if="editOpen" #footer>
              <t-button theme="default" @click="closeDrawer">关闭评审界面</t-button>
              <t-button theme="primary" @click="onSubmit(1)">暂存</t-button>
              <t-button theme="primary" v-if="!closeSubmit" @click="onSubmit(2)">提交</t-button>
            </template>
            <template v-else #footer>
              <t-button theme="default" @click="closeDrawer">取消</t-button>
            </template>
          </t-drawer>
<!--          <t-col :span="3" style="height: 65vh;overflow-y: scroll">-->
<!--            <edit-expert-review @reload="reload" ref="edit-expert-review"  :editOpen="editOpen" :expertEditOpen="expertEditOpen" :reviewType="row.reviewType" :objId="row.id"  :teamId="row.teamId" :expertUserId="row.experts.userId" :visible.sync="dialog.open_review"></edit-expert-review>-->
<!--          </t-col>-->
      </div>
    <template  #footer>
      <t-button theme="default" @click="closeDialog">取消</t-button>
      <t-button v-if="['2'].includes(row.reviewType)" theme="warning" @click="closeDiff=!closeDiff;closeChangeDiff=!closeChangeDiff">{{closeDiff?'打开阶段对比':'关闭阶段对比'}}</t-button>
      <t-button  v-if="['2'].includes(row.reviewType)" theme="warning" @click="closeChangeDiff=!closeChangeDiff;closeDiff=!closeDiff;">{{closeChangeDiff?'打开变更对比':'关闭变更对比'}}</t-button>
      <t-button theme="primary" @click="drawerVisible = true">打开评审界面</t-button>

      <!--      <t-button theme="primary" @click="onSubmit(1)">暂存</t-button>-->
<!--      <t-button theme="primary" @click="onSubmit(2)">提交</t-button>-->
    </template>
<!--    <template v-else #footer>-->
<!--      <t-button theme="default" @click="closeDialog">取消</t-button>-->
<!--    </template>-->
  </t-dialog>
</template>

<script>
import OutlineDetailDialog from "../../../kjxm/outline/components/outline-detail-dialog.vue";
import AcceptanceDetailDialog from "../../../kjxm/acceptance/components/acceptance-detail-dialog.vue";
import EditExpertReview from '../../../kjxm/review/components/edit-expert-review.vue'
import ProjectDetailDialog from "../../../kjxm/pm/components/project-detail-dialog.vue";
import verticalOutlineDetail from "../../../kjxm/outline/components/vertical-outline-detail.vue";
import ItemDetail from "../../../kjxm/pm/components/item-detail.vue";

export default {
  name: "approve-info",
  components:{
    OutlineDetailDialog,
    AcceptanceDetailDialog,
    EditExpertReview,
    ProjectDetailDialog,
    verticalOutlineDetail,
    ItemDetail
  },
  props:["header", "row","expertEditOpen","editOpen","drawerVisibleOpen"],
  data(){
    return {
      closeDiff: false,
      closeChangeDiff: true,
      closeSubmit: false,
      visible: true,
      loading: false,
      drawerVisible: this.drawerVisibleOpen,
      dialog: {
        open_project_detail: false,
        open_outline_detail: false,
        open_contract_detail: false,
        open_review: false
      },
      formData: {
        id: this.objId,
        projectApproval: '1',
        score: null,
        content: '',
        projectItemScores: [],
        sysAttMainVo: {
          sysAttMainIds: []
        }
      },
    }
  },
  mounted() {
    // 在开会前，只能暂存，开会后，就能提交
    if(this.row?.reviewTeam?.reviewMeetingDate){
      const reviewMeetingDate = new Date(this.row.reviewTeam.reviewMeetingDate).getTime()
      const currentDate = new Date().getTime();
      if (currentDate < reviewMeetingDate) {
        this.closeSubmit = true;
      }
    }
  },
  methods:{
    onSubmit(type){
      this.$refs["edit-expert-review"].onSubmit(type)
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
    closeDrawer(){
      this.drawerVisible = false
    },
    reload(type){
      if(type===1){ // 暂存
        this.$emit("reload");
        // this.$emit("update:visible", false);
      }else{
        this.$emit("reload");
        this.$emit("update:visible", false);
      }
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ a{
  margin-right: 10px;
}
::-webkit-scrollbar {
  width: 8px;
  background: transparent;
}

::-webkit-scrollbar-thumb {
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
  background-color: var(--td-scrollbar-color);
}
/deep/ .t-drawer .t-drawer__content-wrapper{
  height: calc(100% - var(--td-comp-size-xxxl));
  margin-top: var(--td-comp-size-xxxl);
}
/deep/ .t-drawer__header{
  display: none;
}
</style>
